/*************************************************************************
*																		 *
*				code by Miles Chen (v-mich) 2007.9.29					 *
*																		 *
*																		 *
*************************************************************************/

#pragma once


class CSalary
{
public:


protected:

	void InitSalaryEditControls(HWND hDlg)
	{
		Controls::SetControlProc(hDlg, IDC_SALARY_BASE,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_SALARY_ALLOW,		(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_SALARY_FOUND_BASE,	(LONG)&FoundBaseProc);
		Controls::SetControlProc(hDlg, IDC_SALARY_PRE_TAX,		(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_SALARY_TAX,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_SALARY_AFTER_TAX,	(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_SALARY_WITH_HOUSE,	(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_SALARY_WITH_ALL,		(LONG)Controls::DefEditDoubleProc);

		Controls::SetControlProc(hDlg, IDC_FOUND_RETIRED_EMPLOYEE_BASE,				(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_MEDIC_EMPLOYEE_BASE,				(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_LOSE_JOB_EMPLOYEE_BASE,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_BIRTH_EMPLOYEE_BASE,				(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_INJURE_EMPLOYEE_BASE,				(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_HOUSE_EMPLOYEE_BASE,				(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_EMPLOYEE_BASE,	(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_OTHER_EMPLOYEE_BASE,				(LONG)Controls::DefEditDoubleProc);

		Controls::SetControlProc(hDlg, IDC_FOUND_RETIRED_COMPANY_BASE,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_MEDIC_COMPANY_BASE,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_LOSE_JOB_COMPANY_BASE,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_BIRTH_COMPANY_BASE,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_INJURE_COMPANY_BASE,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_HOUSE_COMPANY_BASE,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_COMPANY_BASE,	(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_OTHER_COMPANY_BASE,			(LONG)Controls::DefEditDoubleProc);

		Controls::SetControlProc(hDlg, IDC_FOUND_RETIRED_EMPLOYEE_RATE,				(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_MEDIC_EMPLOYEE_RATE,				(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_LOSE_JOB_EMPLOYEE_RATE,			(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_BIRTH_EMPLOYEE_RATE,				(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_INJURE_EMPLOYEE_RATE,				(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_HOUSE_EMPLOYEE_RATE,				(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_EMPLOYEE_RATE,	(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_OTHER_EMPLOYEE_RATE,				(LONG)&FoundRateProc);

		Controls::SetControlProc(hDlg, IDC_FOUND_RETIRED_COMPANY_RATE,			(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_MEDIC_COMPANY_RATE,			(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_LOSE_JOB_COMPANY_RATE,			(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_BIRTH_COMPANY_RATE,			(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_INJURE_COMPANY_RATE,			(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_HOUSE_COMPANY_RATE,			(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_COMPANY_RATE,	(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_FOUND_OTHER_COMPANY_RATE,			(LONG)&FoundRateProc);

		Controls::SetControlProc(hDlg, IDC_TAX_0,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_TAX_500,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_TAX_501,			(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_TAX_2000,		(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_TAX_2001,		(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_TAX_5000,		(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_TAX_5001,		(LONG)Controls::DefEditDoubleProc);
		Controls::SetControlProc(hDlg, IDC_TAX_20000,		(LONG)Controls::DefEditDoubleProc);

		Controls::SetControlProc(hDlg, IDC_TAX_5P,	(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_TAX_10P,	(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_TAX_15P,	(LONG)&FoundRateProc);
		Controls::SetControlProc(hDlg, IDC_TAX_20P,	(LONG)&FoundRateProc);
	}

	void InitTax(HWND hDlg)
	{
		SetDlgItemTextW(hDlg, IDC_TAX_BASE_LINE,		L"2000");

		SetDlgItemTextW(hDlg, IDC_TAX_0,		L"0");
		SetDlgItemTextW(hDlg, IDC_TAX_500,		L"500");
		SetDlgItemTextW(hDlg, IDC_TAX_5P,		L"5%");

		SetDlgItemTextW(hDlg, IDC_TAX_501,		L"500");
		SetDlgItemTextW(hDlg, IDC_TAX_2000,		L"2000");
		SetDlgItemTextW(hDlg, IDC_TAX_10P,		L"10%");

		SetDlgItemTextW(hDlg, IDC_TAX_2001,		L"2000");
		SetDlgItemTextW(hDlg, IDC_TAX_5000,		L"5000");
		SetDlgItemTextW(hDlg, IDC_TAX_15P,		L"15%");

		SetDlgItemTextW(hDlg, IDC_TAX_5001,		L"5000");
		SetDlgItemTextW(hDlg, IDC_TAX_20000,	L"20000");
		SetDlgItemTextW(hDlg, IDC_TAX_20P,		L"20%");
	}

	void SetCityFound(HWND hDlg)
	{
		SetDlgItemTextW(hDlg, IDC_FOUND_RETIRED_EMPLOYEE_RATE,		L"8%");
		SetDlgItemTextW(hDlg, IDC_FOUND_MEDIC_EMPLOYEE_RATE,		L"2%");
		SetDlgItemTextW(hDlg, IDC_FOUND_LOSE_JOB_EMPLOYEE_RATE,		L"1%");
		SetDlgItemTextW(hDlg, IDC_FOUND_BIRTH_EMPLOYEE_RATE,		L"0%");
		SetDlgItemTextW(hDlg, IDC_FOUND_INJURE_EMPLOYEE_RATE,		L"0%");
		SetDlgItemTextW(hDlg, IDC_FOUND_HOUSE_EMPLOYEE_RATE,		L"7%");
		SetDlgItemTextW(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_EMPLOYEE_RATE,		L"0%");
		SetDlgItemTextW(hDlg, IDC_FOUND_OTHER_EMPLOYEE_RATE,		L"0%");

		SetDlgItemTextW(hDlg, IDC_FOUND_RETIRED_COMPANY_RATE,		L"22%");
		SetDlgItemTextW(hDlg, IDC_FOUND_MEDIC_COMPANY_RATE,			L"12%");
		SetDlgItemTextW(hDlg, IDC_FOUND_LOSE_JOB_COMPANY_RATE,		L"2%");
		SetDlgItemTextW(hDlg, IDC_FOUND_BIRTH_COMPANY_RATE,			L"0.5%");
		SetDlgItemTextW(hDlg, IDC_FOUND_INJURE_COMPANY_RATE,		L"0.5%");
		SetDlgItemTextW(hDlg, IDC_FOUND_HOUSE_COMPANY_RATE,			L"7%");
		SetDlgItemTextW(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_COMPANY_RATE,		L"0%");
		SetDlgItemTextW(hDlg, IDC_FOUND_OTHER_COMPANY_RATE,			L"0%");

		SummaryFoundRate(hDlg);
		if(GetDoubleValue(hDlg, IDC_SALARY_AFTER_TAX, FALSE) != 0)
			Calc(hDlg);
	}

	void SetTownFound(HWND hDlg)
	{
		SetDlgItemTextW(hDlg, IDC_FOUND_RETIRED_EMPLOYEE_RATE,		L"0%");
		SetDlgItemTextW(hDlg, IDC_FOUND_MEDIC_EMPLOYEE_RATE,		L"0%");
		SetDlgItemTextW(hDlg, IDC_FOUND_LOSE_JOB_EMPLOYEE_RATE,		L"0%");
		SetDlgItemTextW(hDlg, IDC_FOUND_BIRTH_EMPLOYEE_RATE,		L"0%");
		SetDlgItemTextW(hDlg, IDC_FOUND_INJURE_EMPLOYEE_RATE,		L"0%");
		SetDlgItemTextW(hDlg, IDC_FOUND_HOUSE_EMPLOYEE_RATE,		L"7%");
		SetDlgItemTextW(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_EMPLOYEE_RATE,		L"0%");
		SetDlgItemTextW(hDlg, IDC_FOUND_OTHER_EMPLOYEE_RATE,		L"0%");

		SetDlgItemTextW(hDlg, IDC_FOUND_RETIRED_COMPANY_RATE,		L"17%");
		SetDlgItemTextW(hDlg, IDC_FOUND_MEDIC_COMPANY_RATE,			L"5%");
		SetDlgItemTextW(hDlg, IDC_FOUND_LOSE_JOB_COMPANY_RATE,		L"2%");
		SetDlgItemTextW(hDlg, IDC_FOUND_BIRTH_COMPANY_RATE,			L"0.5%");
		SetDlgItemTextW(hDlg, IDC_FOUND_INJURE_COMPANY_RATE,		L"0.5%");
		SetDlgItemTextW(hDlg, IDC_FOUND_HOUSE_COMPANY_RATE,			L"7%");
		SetDlgItemTextW(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_COMPANY_RATE,		L"0%");
		SetDlgItemTextW(hDlg, IDC_FOUND_OTHER_COMPANY_RATE,			L"0%");

		SummaryFoundRate(hDlg);
		if(GetDoubleValue(hDlg, IDC_SALARY_AFTER_TAX, FALSE) != 0)
			Calc(hDlg);
	}

	static void SummaryFoundRate(HWND hDlg)
	{
		double summary_employee_rate = 0;
		double summary_company_rate = 0;

		summary_employee_rate =
			GetDoubleValue(hDlg, IDC_FOUND_RETIRED_EMPLOYEE_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_MEDIC_EMPLOYEE_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_EMPLOYEE_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_BIRTH_EMPLOYEE_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_INJURE_EMPLOYEE_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_HOUSE_EMPLOYEE_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_EMPLOYEE_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_OTHER_EMPLOYEE_RATE, TRUE) ;

		summary_company_rate =
			GetDoubleValue(hDlg, IDC_FOUND_RETIRED_COMPANY_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_MEDIC_COMPANY_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_COMPANY_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_BIRTH_COMPANY_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_INJURE_COMPANY_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_HOUSE_COMPANY_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_COMPANY_RATE, TRUE) +
			GetDoubleValue(hDlg, IDC_FOUND_OTHER_COMPANY_RATE, TRUE) ;

		SetDoubleValue(hDlg, IDC_FOUND_SUMMARY_EMPLOYEE_RATE, summary_employee_rate * 100, L"%ws%%", 0);
		SetDoubleValue(hDlg, IDC_FOUND_SUMMARY_COMPANY_RATE, summary_company_rate * 100, L"%ws%%", 0);
	}

	void Calc(HWND hDlg)
	{
		double baseSalary, allowSalary, pretaxSalary, tax, afterTax;

		baseSalary = GetDoubleValue(hDlg, IDC_SALARY_BASE, FALSE);
		allowSalary = GetDoubleValue(hDlg, IDC_SALARY_ALLOW, FALSE);

		CalcFound(hDlg);

		pretaxSalary = baseSalary + allowSalary - GetDoubleValue(hDlg, IDC_FOUND_SUMMARY_EMPLOYEE_VALUE, FALSE) ;

		tax = CalcTax(hDlg, pretaxSalary);

		afterTax = pretaxSalary - tax;

		SetDoubleValue(hDlg, IDC_SALARY_PRE_TAX, pretaxSalary, NULL, 2);
		SetDoubleValue(hDlg, IDC_SALARY_TAX, tax, NULL, 2);
		SetDoubleValue(hDlg, IDC_SALARY_AFTER_TAX, afterTax, NULL, 2);
		SetDoubleValue(hDlg, IDC_SALARY_WITH_HOUSE, afterTax + 
			GetDoubleValue(hDlg, IDC_FOUND_HOUSE_SUMMARY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_SUMMARY_VALUE, FALSE), NULL, 2);
		SetDoubleValue(hDlg, IDC_SALARY_WITH_ALL, afterTax + 
			GetDoubleValue(hDlg, IDC_FOUND_SUMMARY_SUMMARY_VALUE, FALSE), NULL, 2);
	}
	void Reset(HWND hDlg)
	{
		SetDlgItemTextW(hDlg, IDC_SALARY_BASE, NULL);
		SetDlgItemTextW(hDlg, IDC_SALARY_ALLOW, NULL);
		SetDlgItemTextW(hDlg, IDC_SALARY_FOUND_BASE, NULL);
		SetDlgItemTextW(hDlg, IDC_SALARY_PRE_TAX, NULL);
		SetDlgItemTextW(hDlg, IDC_SALARY_TAX, NULL);
		SetDlgItemTextW(hDlg, IDC_SALARY_AFTER_TAX, NULL);
		SetDlgItemTextW(hDlg, IDC_SALARY_WITH_HOUSE, NULL);
		SetDlgItemTextW(hDlg, IDC_SALARY_WITH_ALL, NULL);
	}

	double CalcTax(HWND hDlg, double pretax)
	{
		double interval[] = {
			GetDoubleValue(hDlg, IDC_TAX_0, FALSE),
			GetDoubleValue(hDlg, IDC_TAX_500, FALSE),
			GetDoubleValue(hDlg, IDC_TAX_2000, FALSE),
			GetDoubleValue(hDlg, IDC_TAX_5000, FALSE),
			GetDoubleValue(hDlg, IDC_TAX_20000, FALSE)
		};
		double rates[] = {
			GetDoubleValue(hDlg, IDC_TAX_5P, TRUE),
			GetDoubleValue(hDlg, IDC_TAX_10P, TRUE),
			GetDoubleValue(hDlg, IDC_TAX_15P, TRUE),
			GetDoubleValue(hDlg, IDC_TAX_20P, TRUE),
			0.25
		};
		double baseLine = GetDoubleValue(hDlg, IDC_TAX_BASE_LINE, FALSE);

		return CalcTaxImp(pretax, interval, rates, 5, baseLine);
	}

	double CalcTaxImp(double pretax, double* interval, double* rates, int nLen, double baseLine)
	{
		double tax;
		int index;

		if(pretax <= baseLine)
			return 0;

		pretax -= baseLine;

		tax = 0;
		index = nLen - 1;
		while(index >= 0)
		{
			if(pretax > interval[index])
			{
				tax += (pretax - interval[index]) * rates[index];
				pretax = interval[index];
			}
			index --;
		}

		return tax;
	}

	void CalcFound(HWND hDlg)
	{
		SetDoubleValue(hDlg, IDC_FOUND_RETIRED_EMPLOYEE_VALUE, GetDoubleValue(hDlg, IDC_FOUND_RETIRED_EMPLOYEE_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_RETIRED_EMPLOYEE_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_MEDIC_EMPLOYEE_VALUE, GetDoubleValue(hDlg, IDC_FOUND_MEDIC_EMPLOYEE_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_MEDIC_EMPLOYEE_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_EMPLOYEE_VALUE, GetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_EMPLOYEE_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_EMPLOYEE_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_BIRTH_EMPLOYEE_VALUE, GetDoubleValue(hDlg, IDC_FOUND_BIRTH_EMPLOYEE_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_BIRTH_EMPLOYEE_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_INJURE_EMPLOYEE_VALUE, GetDoubleValue(hDlg, IDC_FOUND_INJURE_EMPLOYEE_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_INJURE_EMPLOYEE_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_HOUSE_EMPLOYEE_VALUE, GetDoubleValue(hDlg, IDC_FOUND_HOUSE_EMPLOYEE_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_HOUSE_EMPLOYEE_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_EMPLOYEE_VALUE, GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_EMPLOYEE_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_EMPLOYEE_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_OTHER_EMPLOYEE_VALUE, GetDoubleValue(hDlg, IDC_FOUND_OTHER_EMPLOYEE_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_OTHER_EMPLOYEE_RATE, TRUE), NULL, 2);

		SetDoubleValue(hDlg, IDC_FOUND_RETIRED_COMPANY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_RETIRED_COMPANY_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_RETIRED_COMPANY_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_MEDIC_COMPANY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_MEDIC_COMPANY_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_MEDIC_COMPANY_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_COMPANY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_COMPANY_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_COMPANY_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_BIRTH_COMPANY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_BIRTH_COMPANY_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_BIRTH_COMPANY_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_INJURE_COMPANY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_INJURE_COMPANY_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_INJURE_COMPANY_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_HOUSE_COMPANY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_HOUSE_COMPANY_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_HOUSE_COMPANY_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_COMPANY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_COMPANY_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_COMPANY_RATE, TRUE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_OTHER_COMPANY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_OTHER_COMPANY_BASE, FALSE) * GetDoubleValue(hDlg, IDC_FOUND_OTHER_COMPANY_RATE, TRUE), NULL, 2);

		SetDoubleValue(hDlg, IDC_FOUND_RETIRED_SUMMARY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_RETIRED_EMPLOYEE_VALUE, FALSE) + GetDoubleValue(hDlg, IDC_FOUND_RETIRED_COMPANY_VALUE, FALSE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_MEDIC_SUMMARY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_MEDIC_EMPLOYEE_VALUE, FALSE) + GetDoubleValue(hDlg, IDC_FOUND_MEDIC_COMPANY_VALUE, FALSE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_SUMMARY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_EMPLOYEE_VALUE, FALSE) + GetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_COMPANY_VALUE, FALSE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_BIRTH_SUMMARY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_BIRTH_EMPLOYEE_VALUE, FALSE) + GetDoubleValue(hDlg, IDC_FOUND_BIRTH_COMPANY_VALUE, FALSE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_INJURE_SUMMARY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_INJURE_EMPLOYEE_VALUE, FALSE) + GetDoubleValue(hDlg, IDC_FOUND_INJURE_COMPANY_VALUE, FALSE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_HOUSE_SUMMARY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_HOUSE_EMPLOYEE_VALUE, FALSE) + GetDoubleValue(hDlg, IDC_FOUND_HOUSE_COMPANY_VALUE, FALSE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_SUMMARY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_EMPLOYEE_VALUE, FALSE) + GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_COMPANY_VALUE, FALSE), NULL, 2);
		SetDoubleValue(hDlg, IDC_FOUND_OTHER_SUMMARY_VALUE, GetDoubleValue(hDlg, IDC_FOUND_OTHER_EMPLOYEE_VALUE, FALSE) + GetDoubleValue(hDlg, IDC_FOUND_OTHER_COMPANY_VALUE, FALSE), NULL, 2);

		SetDoubleValue(hDlg, IDC_FOUND_SUMMARY_EMPLOYEE_VALUE, 
			GetDoubleValue(hDlg, IDC_FOUND_RETIRED_EMPLOYEE_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_MEDIC_EMPLOYEE_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_EMPLOYEE_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_BIRTH_EMPLOYEE_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_INJURE_EMPLOYEE_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_HOUSE_EMPLOYEE_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_EMPLOYEE_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_OTHER_EMPLOYEE_VALUE, FALSE), NULL, 2);

		SetDoubleValue(hDlg, IDC_FOUND_SUMMARY_COMPANY_VALUE, 
			GetDoubleValue(hDlg, IDC_FOUND_RETIRED_COMPANY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_MEDIC_COMPANY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_COMPANY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_BIRTH_COMPANY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_INJURE_COMPANY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_HOUSE_COMPANY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_COMPANY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_OTHER_COMPANY_VALUE, FALSE), NULL, 2);

		SetDoubleValue(hDlg, IDC_FOUND_SUMMARY_SUMMARY_VALUE, 
			GetDoubleValue(hDlg, IDC_FOUND_RETIRED_SUMMARY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_MEDIC_SUMMARY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_LOSE_JOB_SUMMARY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_BIRTH_SUMMARY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_INJURE_SUMMARY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_HOUSE_SUMMARY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_ADDITIONAL_HOUSE_SUMMARY_VALUE, FALSE) + 
			GetDoubleValue(hDlg, IDC_FOUND_OTHER_SUMMARY_VALUE, FALSE), NULL, 2);
	}

	static double GetDoubleValue(HWND hDlg, int nIDDlgItem, BOOL fPercentage)
	{
		return GetDoubleValue(GetDlgItem(hDlg, nIDDlgItem), fPercentage);
	}

	static double GetDoubleValue(HWND hwndEdit, BOOL fPercentage)
	{
		WCHAR szBuffer[SHORT_CHAR];
		SendMessageW(hwndEdit, WM_GETTEXT, SHORT_CHAR, (LPARAM)szBuffer);

		if(fPercentage)
		{
			szBuffer[ wcslen(szBuffer) - 1 ] = L'\0';	//remove '%' at the end of string.
			return _wtof(szBuffer) / 100;
		}
		else 
			return _wtof(szBuffer);
	}

	static void SetDoubleValue(HWND hDlg, int nIDDlgItem, double value, LPWSTR lpszFormatString, int decimal)
	{
		WCHAR szText[MAX_CHAR];
		WCHAR szBuffer[SHORT_CHAR];

		Convert::DoubleToString(szBuffer, value, decimal);

		if(lpszFormatString)
			wsprintfW(szText, lpszFormatString, szBuffer);
		else
			String::CopyTo(szText, szBuffer);

		SetDlgItemTextW(hDlg, nIDDlgItem, szText);
	}

private:
	static LRESULT CALLBACK FoundBaseProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
	{
		if(message == WM_CHAR && wParam != '.' && (wParam < '0' || wParam > '9') && wParam != VK_BACK )
		{
			MessageBeep(MB_OK);
			return 0;
		}
		else if(message == WM_CHAR)
		{
			LRESULT lr = CallWindowProcW((WNDPROC)GetWindowLongW(hWnd, GWL_USERDATA), hWnd, message, wParam, lParam);

			//
			double value = GetDoubleValue(hWnd, FALSE);

			SetDoubleValue(GetParent(hWnd), IDC_FOUND_RETIRED_EMPLOYEE_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_MEDIC_EMPLOYEE_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_LOSE_JOB_EMPLOYEE_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_BIRTH_EMPLOYEE_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_INJURE_EMPLOYEE_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_HOUSE_EMPLOYEE_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_ADDITIONAL_HOUSE_EMPLOYEE_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_OTHER_EMPLOYEE_BASE, value, NULL, 2);

			SetDoubleValue(GetParent(hWnd), IDC_FOUND_RETIRED_COMPANY_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_MEDIC_COMPANY_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_LOSE_JOB_COMPANY_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_BIRTH_COMPANY_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_INJURE_COMPANY_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_HOUSE_COMPANY_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_ADDITIONAL_HOUSE_COMPANY_BASE, value, NULL, 2);
			SetDoubleValue(GetParent(hWnd), IDC_FOUND_OTHER_COMPANY_BASE, value, NULL, 2);

			return lr;
		}
		else 
		{
			return CallWindowProcW((WNDPROC)GetWindowLongW(hWnd, GWL_USERDATA), hWnd, message, wParam, lParam);
		}
	}

	static LRESULT CALLBACK FoundRateProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
	{
		if(message == WM_CHAR && wParam != '.' && (wParam < '0' || wParam > '9') && wParam != VK_BACK && wParam != '%')
		{
			MessageBeep(MB_OK);
			return 0;
		}
		else if(message == WM_CHAR)
		{
			LRESULT lr = CallWindowProcW((WNDPROC)GetWindowLongW(hWnd, GWL_USERDATA), hWnd, message, wParam, lParam);

			SummaryFoundRate(GetParent(hWnd));

			return lr;
		}
		else 
		{
			return CallWindowProcW((WNDPROC)GetWindowLongW(hWnd, GWL_USERDATA), hWnd, message, wParam, lParam);
		}
	}
};
